package com.my.aslife.controller;

import com.my.aslife.module.common.ResponseResult;
import com.my.aslife.module.entity.Dict;
import com.my.aslife.module.entity.dtos.DictDto;
import com.my.aslife.service.IDictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author mayuan
 * @description TODO
 */
@RestController
@Slf4j
@RequestMapping("/api/my/dict")
@CrossOrigin(origins = "*")
public class DictController {

    @Autowired
    private IDictService IDictService;

    @GetMapping("/type/{id}/info")
    public ResponseResult<List<DictDto>> getTypeListByCondition(@PathVariable("id") Integer id){
        List<Dict> list = IDictService.getTypeListByCondition(id);
        List<DictDto> result = new ArrayList<>(list.size());
        list.forEach(data -> {
            DictDto dictDto = new DictDto();
            BeanUtils.copyProperties(data, dictDto);
            result.add(dictDto);
        });

        return ResponseResult.ok(result);
    }
}
